package ru.st.selenium.pages;

import java.lang.reflect.Field;

import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.pagefactory.AjaxElementLocator;

public class AlertAndGetItsText extends InternalPage {

	private boolean acceptNextAlert;
	public AlertAndGetItsText(PageManager pages) {
		super(pages);
	}
	public String closeAlertAndGetItsText() {
        try {
          Alert alert = driver.switchTo().alert();
          String alertText = alert.getText();
          if (acceptNextAlert) {
            alert.accept();
          } else {
            alert.dismiss();
          }
          return alertText;
        } finally {
          acceptNextAlert = true;
        }
      }
}
